/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.processing;

import aiaudio.lastfm.hbase.CannotCreateTableException;
import aiaudio.database.DatabaseStorage;
import aiaudio.database.tablegroup.InitialDataTableGroup;
import aiaudio.database.tablegroup.NetworkAlgTableGroup;
import aiaudio.database.tablegroup.PrepareRatingsAlgTableGroup;
import aiaudio.database.tablegroup.RatingPredictionAlgTableGroup;
import aiaudio.database.tablegroup.ReduceArtistsAlgTableGroup;
import aiaudio.database.tablegroup.SplitDataSetAlgTableGroup;
import aiaudio.database.tablegroup.StatisticsTableGroup;
import java.io.IOException;

/**
 *
 * @author nastya
 */
public class MainTableGroup{

    private String key;
    
    private InitialDataTableGroup initialDataTableGroup = InitialDataTableGroup.getInstance();
    private NetworkAlgTableGroup networkAlgTableGroup;
    private PrepareRatingsAlgTableGroup prepareRatingsAlgTableGroup;
    private RatingPredictionAlgTableGroup ratingPredictionAlgTableGroup;
    private ReduceArtistsAlgTableGroup reduceArtistsAlgTableGroup;
    private SplitDataSetAlgTableGroup splitDataSetAlgTableGroup;
    private StatisticsTableGroup statisticsTableGroup;
    private final ProcessingStage processingStage;
    
    public MainTableGroup(String key, ProcessingStage processingStage) {
        this.key = key;
        this.processingStage = processingStage;
        initGroups(key);
    }

    public MainTableGroup(String key) {
        this(key, ProcessingStage.SplitData);
    }

    public InitialDataTableGroup getInitialDataTableGroup() {
        return initialDataTableGroup;
    }

    public NetworkAlgTableGroup getNetworkAlgTableGroup() {
        return networkAlgTableGroup;
    }

    public PrepareRatingsAlgTableGroup getPrepareRatingsAlgTableGroup() {
        return prepareRatingsAlgTableGroup;
    }

    public RatingPredictionAlgTableGroup getRatingPredictionAlgTableGroup() {
        return ratingPredictionAlgTableGroup;
    }

    public ReduceArtistsAlgTableGroup getReduceArtistsAlgTableGroup() {
        return reduceArtistsAlgTableGroup;
    }

    public SplitDataSetAlgTableGroup getSplitDataSetAlgTableGroup() {
        return splitDataSetAlgTableGroup;
    }

    public StatisticsTableGroup getStatisticsTableGroup() {
        return statisticsTableGroup;
    }
    
    
    
    private void initGroups(String key) {
        splitDataSetAlgTableGroup = new SplitDataSetAlgTableGroup(key, isSplitRecreationNeeded());
        prepareRatingsAlgTableGroup = new PrepareRatingsAlgTableGroup(key, isNormilizedRatingsRecreationNeeded());
        reduceArtistsAlgTableGroup = new ReduceArtistsAlgTableGroup(key, isReduceRecreationNeeded());
        networkAlgTableGroup = new NetworkAlgTableGroup(key, isNetworkRecreationNeeded());
        ratingPredictionAlgTableGroup = new RatingPredictionAlgTableGroup(key, isPredictionRecreationNeeded());
        statisticsTableGroup = new StatisticsTableGroup(key);
    }

    private boolean isSplitRecreationNeeded() {
        return processingStage.compareStage(ProcessingStage.SplitData) <= 0;
    }
    private boolean isNetworkRecreationNeeded() {
        return processingStage.compareStage(ProcessingStage.CalculateNetwork) <= 0;
    }
    private boolean isNormilizedRatingsRecreationNeeded() {
        return processingStage.compareStage(ProcessingStage.CalculateRatings) <= 0;
    }
    private boolean isPredictionRecreationNeeded() {
        return processingStage.compareStage(ProcessingStage.MakeRecomendation) <= 0;
    }
    private boolean isReduceRecreationNeeded() {
        return processingStage.compareStage(ProcessingStage.ReduceData) <= 0;
    }

    
}
